package com.gxa.ehome.service.impl;


import com.gxa.ehome.entity.PageBean;
import com.gxa.ehome.mapper.SysUserMapper;
import com.gxa.ehome.pojo.SysUser;
import com.gxa.ehome.service.SysUserservice;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("sysUserService")
@Transactional(rollbackFor = Throwable.class)
public class SysUserServlceImpl implements SysUserservice {

    @Resource(name = "sysUserMapper")
    private SysUserMapper sysUserMapper = null;

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public PageBean<SysUser> selectByPage(int page, int limit) {
        //获取分页查询的所有记录：List
        List<SysUser> sysUsers = sysUserMapper.selectByPage((page - 1) * limit, limit);

        //获取记录总数
        int count = sysUserMapper.selectCount();

        //将mapper查询的结果组装
        PageBean<SysUser> pageBean = new PageBean<>();
        pageBean.setDataList(sysUsers);
        pageBean.setCount(count);

        return pageBean;
    }

}
